package com.lcj.demo.web;

import com.lcj.demo.domain.Job;
import com.lcj.demo.service.JobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(value = "工作", description = "工作相关操作Api")
@RestController
@RequestMapping("/api")
public class JobController {
    private final JobService jobService;

    public JobController(JobService jobService) {
        this.jobService = jobService;
    }

    @ApiOperation(value="获取所有工作", notes="获取所有工作")
    @GetMapping("/jobs")
    public List<Job> findAll() {
        return jobService.findAll();
    }

    @ApiOperation(value="创建工作信息", notes="创建工作信息")
    @ApiImplicitParam(name = "Job", value = "详细实体", required = true, dataType = "Job")
    @PostMapping("/job")
    public Job create(@RequestBody Job job) {
        return jobService.saveOrUpdate(job);
    }

    @ApiOperation(value="更新工作信息", notes="更新工作信息")
    @ApiImplicitParam(name = "Job", value = "详细实体", required = true, dataType = "Job")
    @PutMapping("/job")
    public Job update(@RequestBody Job job) {
        return jobService.saveOrUpdate(job);
    }

    @ApiOperation(value="删除工作信息", notes="删除工作信息")
    @ApiImplicitParam(name = "ID", value = "工作id", required = true, dataType = "Long")
    @DeleteMapping("/job/{id}")
    public void delete(@PathVariable("id") Long id) {
        jobService.delete(id);
    }

}
